#include "stdafx.h"
#include "code/digestengine.hpp"

namespace JHCPP
{
	namespace code
	{
		CDigestEngine::CDigestEngine()
		{
		}

		CDigestEngine::~CDigestEngine()
		{
		}

		void CDigestEngine::update(const void* data, unsigned length)
		{
			updateImpl(data, length);
		}

		void CDigestEngine::update(char data)
		{
			updateImpl(&data, 1);
		}

		void CDigestEngine::update(const std::string& data)
		{
			updateImpl(data.data(), (unsigned) data.size());	
		}

		std::string CDigestEngine::digestToHex(const Digest& bytes)
		{
			static const char digits[] = "0123456789abcdef";
			std::string result;
			result.reserve(bytes.size()*2);
			for (Digest::const_iterator it = bytes.begin(); it != bytes.end(); ++it)
			{
				unsigned char c = *it;
				result += digits[(c >> 4) & 0xF];
				result += digits[c & 0xF];
			}
			return result;
		}
	}//end of namespace code
}//end of namespace JHCPP
